<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    String actionURL = path + "/cms/customer/doQuery.do";
%>
<!doctype html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<base href="<%=basePath%>">
		<title>用户管理</title>
		
		<link href="css/css-main.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="css/msgbox/jquery.msgbox.css" />
		<script type="text/javascript" src="js/jquery.min.js">
</script>
		<script type="text/javascript" src="js/msgbox/jquery.dragndrop.min.js">
</script>
		<script type="text/javascript" src="js/msgbox/msgbox.js">
</script>
		<script type="text/javascript" src="js/common.js">
</script>
		<script type="text/javascript" src="js/cardInterface.js">
</script>
		
		 
		<script language="javascript" type="text/javascript">
		//获取已选择的记录项
		function getCheckbox()
		{
			var inputs = document.getElementsByTagName("input");
			var checkboxCheckedArray = [];
			for(var i=0;i<inputs.length;i++)
			{
			  var obj = inputs[i];
			  if(obj.type=='checkbox' && obj.checked){
				  checkboxCheckedArray.push(obj);
			  }
			}
			return checkboxCheckedArray;
		}
		 
		//查询
		function doSearch() {

			var queryKey = document.getElementById("queryConditon_key").value;
			var queryValue = document.getElementById("queryConditon_value").value;
			
			var form = document.getElementById('regform');
			form.action = "cms/manager/doQuery.do?searchName="+queryKey+"&searchValue="+queryValue;
			form.submit();
		}
		//修改用户
		function modUser() {
			var checkArray = getCheckbox();
			var count = 0;
			var checkboxCheckedArray = [];
			for(var i=0;i<checkArray.length;i++)
			{
			  var obj = checkArray[i];
			  if(obj.type=='checkbox' && obj.checked){
				  checkboxCheckedArray.push(obj);
				  count++;
			  }
			}
			if (count > 0) {
				if(count == 1){
					var userId = checkboxCheckedArray[0].value;
					var form = document.getElementById('regform');
					form.action = "cms/manager/toModUser.do?user.userId=" + userId;
					form.submit();
					 
				}else{
					window.alert("请选择一个用户！不能选择多个用户！");
				}
			} else {
				window.alert("请选择用户！");
			}
		}
		//查看用户详细信息
		function getUser() {
			var checkArray = getCheckbox();
			var count = 0;
			var checkboxCheckedArray = [];
			for(var i=0;i<checkArray.length;i++)
			{
			  var obj = checkArray[i];
			  if(obj.type=='checkbox' && obj.checked){
				  checkboxCheckedArray.push(obj);
				  count++;
			  }
			}
			
			if (count > 0) {
				if(count == 1){
					var userId = checkboxCheckedArray[0].value;
					var form = document.getElementById('regform');
					form.action = "cms/manager/detailUser.do?user.userId=" + userId;
					form.submit();
				}else{
					window.alert("请选择一个用户！不能选择多个用户!");
				}
			} else {
				window.alert("请选择用户！");
			}
		}
		//启动用户
		function startUser() {
			var checkArray = getCheckbox();
			var userIds = "";
			var checkboxCheckedArray = [];
			for(var i=0;i<checkArray.length;i++)
			{
			  var obj = checkArray[i];
			  if(obj.type=='checkbox' && obj.checked){
				  checkboxCheckedArray.push(obj);
				  userIds += checkboxCheckedArray[i].value + ",";
			  }
			}
			if (userIds != "") {
				var form = document.getElementById('regform');
				form.action = "cms/manager/startUser.do?userIds=" + userIds;
				form.submit();
			} else {
				window.alert("请选择用户！");
			}
		}
		//停用用户
		function stopUser() {
			var checkArray = getCheckbox();
			var userIds = "";
			var checkboxCheckedArray = [];
			for(var i=0;i<checkArray.length;i++)
			{
			  var obj = checkArray[i];
			  if(obj.type=='checkbox' && obj.checked){
				  checkboxCheckedArray.push(obj);
				  userIds += checkboxCheckedArray[i].value + ",";
			  }
			}
			if (userIds != "") {
				var form = document.getElementById('regform');
				form.action = "cms/manager/stopUser.do?userIds=" + userIds;
				form.submit();
			} else {
				window.alert("请选择用户！");
			}
		}
		//对用户授权
		function grantUser() {
			var checkArray = getCheckbox();
			var userIds = "";
			var checkboxCheckedArray = [];
			for(var i=0;i<checkArray.length;i++)
			{
			  var obj = checkArray[i];
			  if(obj.type=='checkbox' && obj.checked){
				  checkboxCheckedArray.push(obj);
				  userIds += checkboxCheckedArray[i].value + ",";
			  }
			}
			if (userIds != "") {
				var form = document.getElementById('regform');
				form.action = "userAction!toGrantUser.do?userIds=" + userIds;
				form.submit();
			} else {
				window.alert("请选择用户！");
			}
		}

		//显示高级查询div
		function changeDivStatus()
		{
			var obj = document.getElementById('advanceCondition');

				if(obj.style.display == 'none')
				{
					obj.style.display = 'block';
				}else{
					obj.style.display = 'none';
				}
				
		}
		//分页：首页、上一页、下一页、尾页
		function queryFirst(){
		 	var form = document.getElementById("regform");
		 	document.getElementById("pageIndex").value=1;
		 	form.submit();
		}
		
		function queryNext(){
		 	var form = document.getElementById("regform");
		 	var next = Number(document.getElementById("pageIndex").value)+1;
		 	document.getElementById("pageIndex").value=next;
		 	form.submit();
		
		}
		
		function queryPre(){
		 	var form = document.getElementById("regform");
		 	var pre = Number(document.getElementById("pageIndex").value)-1;
		 	document.getElementById("pageIndex").value=pre;
		 	form.submit();
		
		}
		
		function queryLast(){
		 	var form = document.getElementById("regform");
		 	var totalPage = Number(document.getElementById("totalPage").value);
		 	document.getElementById("pageIndex").value=totalPage;
		 	form.submit();
		}


		//增加用户
		function addUser(){
			//var navi = chooseNavigator();

			var form = document.getElementById('regform');
			form.action = "cms/manager/toAddUser.do";
			form.submit();
		}
		
		/**
		* 浏览器判断
		**/
		function chooseNavigator(){
	        var Sys = {}; 
	        var ua = navigator.userAgent.toLowerCase(); 
	        var s; 
	        (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 
	        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : 
	        (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : 
	        (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : 
	        (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0; 
	
	        //以下进行测试 
	        /**
	        if (Sys.ie) document.write('IE: ' + Sys.ie); 
	        if (Sys.firefox) document.write('Firefox: ' + Sys.firefox); 
	        if (Sys.chrome) document.write('Chrome: ' + Sys.chrome); 
	        if (Sys.opera) document.write('Opera: ' + Sys.opera); 
	        if (Sys.safari) document.write('Safari: ' + Sys.safari); 
			**/
	        //alert("s:"+s[1]);
	        return s;
		}

		//当用户为admin时，可以对所有用户的密码进行重置，即恢复为默认密码123456；
		function resetPassword(){
			var checkArray = getCheckbox();
			var count = 0;
			var checkboxCheckedArray = [];
			for(var i=0;i<checkArray.length;i++)
			{
			  var obj = checkArray[i];
			  if(obj.type=='checkbox' && obj.checked){
				  checkboxCheckedArray.push(obj);
				  count++;
			  }
			}
			
			if (count > 0) {
				if(count == 1){
					var userId = checkboxCheckedArray[0].value;
					var form = document.getElementById('resetPasswordT');
					form.action = "cms/manager/changeUserPwd.do?user.userId=" + userId+"&user.userPwd="+"123456";
					form.submit();
				}else{
					window.alert("请选择一个用户！不能选择多个用户!");
				}
			} else {
				window.alert("请选择用户！");
			}
		}
		</script>

	</head>
		<div class="main-con">
			<!--//导航位置层-->
			<div class="main-bar">
				<span class="bar-position">当前位置：<a href="#">首页</a> 》 系统管理 》
					用户管理</span>
			</div>
			<div >
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr>
					    <td>
						<div align="left">
							<s:set var="userNameT">${LOGIN_USER.userName}</s:set>
							<s:if test=" #userNameT == 'admin'">
								<input name="button5" type="button" class="btn-Yes" id="button5"
									value="增加" onclick="addUser()" />
								<input name="button2" type="button" class="btn-Yes" id="button2"
									value="停用" onclick="stopUser()" />
								<input name="button4" type="button" class="btn-Yes" id="button4"
									value="启用" onclick="startUser()" />
								<input name="button3" type="button" class="btn-Yes" id="button3"
									value="修改" onclick="modUser()" />
								<input name="button1" type="button" class="btn-Yes" id="button1"
									value="恢复密码" onclick="resetPassword()" />
							</s:if>
							<input name="button1" type="button" class="btn-Yes" id="button1"
								value="查看" onclick="getUser()" />
						</div>
					      </td>
						<td height="40" align="right" valign="middle">
						<select  class="data-searchtxt-select" id="queryConditon_key" style="width:150px">
								<option value="userName" selected="selected">用户名</option>
								<option value="userMobile">电话号码</option>
						</select>
						</td>
						<td width="150" align="right" valign="middle">
						 <span style="padding:0px"> 
						  <input  type="text" class="data-searchtxt-runtime" id="queryConditon_value" />
						 </span>
						</td>
						<td width="100" align="right" valign="middle">
						<input name="queryBtn" type="button" class="data-searchbtn" id="queryBtn" value="查 询" onclick="doSearch()"  />
						</td>
					</tr>
				</table>
			</div>
			<s:form method="post"  
				id="resetPasswordT" target="_parent">
			</s:form>
			<s:form method="post" action="cms/manager/doQuery.do"
				id="regform">
				<!-- 分页 隐藏域:当前页、总页数 -->
				<input name="pageIndex" value="<s:property value="pageIndex"/>"
					id="pageIndex" type="hidden" />
				<input name="page.totalPage"
					value="<s:property value="page.totalPage"/>" id="totalPage"
					type="hidden" />
				<div class="cont-div">
					<table width="100%" border="0" cellspacing="0" cellpadding="0"
						class="datalist">
						<tr>
							<th width="4%">
								<input type="checkbox" name="checkbox" id="checkbox" />
							</th>
							<th>
								序号
							</th>
							<th>
								用户名
							</th>
							<th>
								状态
							</th>
							<th>
								邮箱
							</th>
							<th>
								性别
							</th>
							<th>
								电话号码
							</th>
							<th width="35%">
								备注
							</th>
						</tr>
						<s:iterator value="userList" status="index" var="user">
							<tr>
								<td>
									<input type="checkbox" name="checkbox" id="checkbox"
										value="<s:property value='userId' />" />
								</td>
								<td>
									<s:property value="#index.count" />
								</td>
								<td>
									<s:property value="userName" />
								</td>
								<td>
									<s:if test="userState==0">
												启用
												</s:if>
									<s:elseif test="userState==1">
												停用
												</s:elseif>
									<s:else>已删除
												</s:else>
								</td>
								<td>
									<s:property value="userEmail" />
								</td>
								<td>
									<s:if test="userMale==0">
												男
												</s:if>
									<s:elseif test="userMale==1">
												女
												</s:elseif>
								</td>
								<td>
									<s:property value="userMobile" />
								</td>
								<td>
									<s:if test="userNote.length()>28">
										<s:property value="userNote.substring(0,28)+'...'" />
									</s:if>
									<s:else>
										<s:property value="userNote" />
									</s:else>
								</td>
							</tr>
						</s:iterator>
					</table>
					<div class="page-div">
						<div class="manu">
							<s:property value="page.pageBottom" escape="false" />
						</div>
					</div>
				</div>
			</s:form>
		</div>
</html>
